package com.wentao.mall.controller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wentao.mall.commons.Result;
import com.wentao.mall.model.vo.OrderVo;
import com.wentao.mall.service.BackService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class BackController {
    @Autowired
    private BackService backService;

    @ApiOperation("后台订单列表")
    @GetMapping("/admin/order/list")
    public Result orderListAll(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<OrderVo> orderVoList=backService.orderListAll();
        PageInfo pageInfo = new PageInfo(orderVoList);
        return Result.success(pageInfo);
    }

    @ApiOperation("订单发货")
    @PostMapping("/admin/order/delivered")
    public Result orderDelivered(@RequestParam("orderNo") String orderNo){
        backService.orderDelivered(orderNo);
        return Result.success("发货成功");
    }

    @ApiOperation("订单完结")
    @PostMapping("/order/finish")
    public Result orderFinish(@RequestParam("orderNo") String orderNo){
        backService.orderFinish(orderNo);
        return Result.success("订单完结成功");
    }
}
